//============================================================================
// Copyright (C) 2003-2013 Brett R. Jones 
// All Rights Reserved
//
// You may redistribute and/or modify for non commercial and commercial uses 
// provided this copyright notice remains in place and is not modified
//
// This code is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
//
// brettjones1900@gmail.com
// http://www.p2panarchy.com
//============================================================================
#include "RcSysPktLib.h"



void RcSysPktAuth::AddMsg( std::string & csMsg )
{
	m_u16PktLen = 16;
	m_u16MsgLen = 0;
	int iMsgLen = (int)csMsg.size();
	if( iMsgLen )
	{
		if( iMsgLen > RC_SYS_PKT_AUTH_MAX_MSG_LEN )
		{
			strncpy( (char *)m_au8Additional, csMsg.c_str(), RC_SYS_PKT_AUTH_MAX_MSG_LEN );
			m_au8Additional[ RC_SYS_PKT_AUTH_MAX_MSG_LEN ] = 0;
			m_u16MsgLen = (U16 ) RC_SYS_PKT_AUTH_MAX_MSG_LEN;
		}
		else
		{
			strncpy( (char *)m_au8Additional, csMsg.c_str(), iMsgLen + 1 );
			m_u16MsgLen = (U16 ) iMsgLen;
		}
		m_u16PktLen += m_u16MsgLen;
		m_u16PktLen = ROUND_TO_16BYTE_BOUNDRY( m_u16PktLen );
	}


}
void RcSysPktAuth::GetMsg( std::string & csRetMsg )
{
	if( m_u16MsgLen )
	{
		vx_assert( m_u16MsgLen <= RC_SYS_PKT_AUTH_MAX_MSG_LEN + 1 );
		csRetMsg = (char *)m_au8Additional;
	}
	else
	{
		csRetMsg = "";
	}
}

